#!/bin/sh
# This regression test is a part of SIPp.
# The status code of a message is read from its first line only: a
# message whose first line has no space or tab is no response, whatever
# its other lines or an earlier, longer message hold, but a request.
. "`dirname "$0"`/../functions"; init

sippbg -sf uas.xml -i 127.0.0.1 -p 27430 -m 2 -timeout 2 -trace_err \
    -error_file errors.log
perl -e '
    use Socket;
    socket(S, PF_INET, SOCK_DGRAM, 17) || die $!;
    $to = pack_sockaddr_in(27430, inet_aton("127.0.0.1"));
    send(S, "SIP/2.0\r\nCall-ID:a\r\nX-Pad:" . ("x" x 60) . " 486\r\n\r\n", 0, $to);
    select(undef, undef, undef, 0.2);
    send(S, "SIP/2.0\r\nCall-ID:b\r\n\r\n", 0, $to);'
wait
errors=`cat errors.log 2>/dev/null`
rm -f errors.log

case "$errors" in
*"unexpected message for Call-Id 'a'"*"unexpected message for Call-Id 'b'"*)
    ok;;
*)
    fail "a message without a blank in its first line was not taken as a request";;
esac
